<template>
	<view class="user_register_password_page">
		<view class="page_content">
			<form class="form_block" @submit="formSubmit">
				<view class="margin-left-30 padding-right-30 flex align-center line-height-100 border-bottom-ed">
					<text class="text text-28 text-1a">手机号</text>
					<input class="margin-left-25 flex-one" type="number" name="mobile_phone" maxlength="11"
						v-model="mobile_phone" placeholder="请输入手机号" placeholder-class="text-28 text-aa" />
				</view>

				<view class="margin-left-30 padding-right-30 flex align-center line-height-100 border-bottom-ed">
					<text class="text text-28 text-1a">验证码</text>
					<input class="margin-lr-25 flex-one" type="number" name="code" maxlength="4" placeholder="请输入验证码"
						placeholder-class="text-28 text-aa" />
					<ty-register-get-code :mobile-phone="mobile_phone" :type="3"></ty-register-get-code>
				</view>

				<view class="margin-left-30 padding-right-30 flex align-center line-height-100 border-bottom-ed">
					<text class="text text-28 text-1a">新密码</text>
					<input class="margin-left-25 flex-one" type="password" name="password" maxlength="20"
						placeholder="请输入新密码" placeholder-class="text-28 text-aa" />
				</view>

				<view class="padding-lr-30 flex align-center line-height-100 border-bottom-ed">
					<text class="text text-28 text-1a">确认密码</text>
					<input class="margin-left-25 flex-one" type="password" name="password_confirm" maxlength="20"
						placeholder="请再次输入新密码" placeholder-class="text-28 text-aa" />
				</view>

				<view class="margin-top-100 text-center text-24 text-98">确认后,将用新密码进行登录</view>

				<button form-type="submit"
					class="margin-top-40 margin-lr-30 line-height-90 radius-45 bg-main-gradient text-center text-32 text-ff">
					确认
				</button>
			</form>
		</view>
	</view>
</template>

<script>
	import user from "../api/user.js"
	export default {
		data() {
			return {
				mobile_phone: ''
			}
		},

		onLoad(options) {
			let type = options.type || 0;
			if (type == 2) {
				this.cn.setTitle('忘记密码')
			}
		},

		methods: {
			// 确认修改密码
			formSubmit(e) {
				if (!e.detail.value.mobile_phone) {
					this.cn.toast("请输入手机号")
					return false
				}
				if (!e.detail.value.code) {
					this.cn.toast("请输入验证码")
					return false
				}
				if (!e.detail.value.password) {
					this.cn.toast("请输入新密码");
					return false;
				}
				if (!e.detail.value.password_confirm) {
					this.cn.toast("请再次输入新密码");
					return false;
				}
				if (e.detail.value.password !== e.detail.value.password_confirm) {
					this.cn.toast("您输入的两次密码不同");
					return false;
				}

				// 获取用户手机号
				user.updatePassword(e.detail.value.mobile_phone, e.detail.value.code, e.detail.value.password, e.detail
					.value.password_confirm).then(res => {
					if (res.code === 0) {
						uni.navigateBack({
							delta: 1
						})
					}
				})
			}
		}
	}
</script>

<style>
	page {
		background: #fff;
	}

	.text {
		width: 112rpx;
	}
</style>
